<template>
    <div class="tixian">
        <div class="tixian-panel">
            <div class="tixian-money">
                <span>可提现金额（元）</span>
                <span class="cell-right">¥{{totalMoney}}</span>
            </div>
            <div class="tixian-source" style="margin-bottom: .16rem;">
                <p class="tixian-source-item">{{backInfo.bankName}}</p>
                <p class="tixian-source-item">{{backInfo.bankAccount}}</p>
            </div>
            <div class="tixian-source">
                <p class="tixian-source-item" style="font-weight:bold;">提现金额（收取0.3%的手续费）</p>
                <p class="tixian-source-item" style="font-weight:bold;">¥ <input type="text" v-model="money"></p>
            </div>
        </div>
        <div class="tixian-container">
                 <div class="tixian-tip">
                    <span>单笔提现额度不能低于￥10000.00元</span>
                    <span class=" cell-right" style="color: #29abae; " @click="allTixian()">全部提现</span>
                </div>
        </div>
        <div class="confrim-btn" @click="addRecord()">确认提现</div>
    </div>
</template>
<script>
import { post } from '../../../../util/http.js'
import { Toast } from 'mint-ui'
export default {
    data() {
        return { 
            totalMoney: '',
            money: '',
            backInfo: {}
        }
    },
    mounted() {
        this.$nextTick(()=>{
            this.bankInfo()
        })
    },
    methods: {
        bankInfo() {
            let info = JSON.parse(window.localStorage.getItem('dongHang_data'))
            post('http://dlsapi.rz158.com/putForward/bankInfo', {
                agentId: info.agentId
            }).then(res => {
                if(res.code == 0) {
                    this.backInfo = res.t
                    this.totalMoney = res.v
                } else {
                    Toast({
                        message: res.message,
                        duration: 1000
                    })
                }
            })
        },
        allTixian() {
            this.money = this.totalMoney 
        },
        addRecord() {
            console.log(parseFloat(this.money))
            let info = JSON.parse(window.localStorage.getItem('dongHang_data'))
            if (this.money == '' || parseFloat(this.money) > parseFloat(this.totalMoney)) {
                 Toast({
                        message: '请输入有效的提现金额',
                        duration: 1000
                    })
            } else if(parseFloat(this.money) < 10000) {
                Toast({
                    message: '余额小于10000无法提现',
                    duration: 1000
                })
            } else {
                if(String(this.money).indexOf('.') != -1) {
                    let length = (this.money.length - 1) - this.money.indexOf('.')
                    post('http://dlsapi.rz158.com/putForward/addRecord', {
                        agentId: info.agentId,
                        bankId: this.backInfo.id,
                        amount: parseFloat(this.money) * 100 * length
                    }).then(res => {
                        if(res.code == 0) {
                            Toast({
                                message:'提现已发起',
                                duration: 1000
                            })
                            this.$router.push('/tixian_record')
                        } else {
                            Toast({
                                message: res.message,
                                duration: 1000
                            })
                         }
                    })
                } else {
                    post('http://dlsapi.rz158.com/putForward/addRecord', {
                        agentId: info.agentId,
                        bankId: this.backInfo.id,
                        amount: parseFloat(this.money) * 100
                    }).then(res => {
                        if(res.code == 0) {
                            Toast({
                                message:'提现已发起',
                                duration: 1000
                            })
                            this.$router.push('/tixian_record')
                        } else {
                            Toast({
                                message: res.message,
                                duration: 1000
                            })
                         }
                    })
                }
            }
        }
    }
}
</script>

<style lang="less" scoped>
    .tixian {
        border-top: 2px soild #cccccc;
        width: 100%;
        height: 100vh;
        background: #ffffff;
        .cell-right {
            float: right;
        }
        .tixian-panel {
            background: #efefef;
            height: 4.04rem;
            .tixian-money {
                padding: 0rem .3rem;
                background: #ffffff;
                height: 1rem;
                line-height: 1rem;
                font-size: .3rem;
                margin-bottom: .16rem;
            }
            .tixian-source{
                padding: .16rem .3rem;
                background: #ffffff;
                font-size: .3rem;
                height: 1.04rem;
                .tixian-source-item{
                    padding: .04rem;
                    input{
                        border: 0px;
                        outline: none;
                        width: 6.4rem;
                        font-size: 0.3rem;
                    }
                }
            }
        }
        .tixian-container{
            padding: 0rem .3rem;
            .tixian-tip{
                border-top: 1px solid #cccccc;
                padding: .2rem 0rem;
                font-size: .24rem;
                color: #707070;
            }
        }   
        .confrim-btn{
            margin-top: .6rem!important;
            background: #29abae;
            font-size: .32rem;
            height: .8rem;
            width: 6.9rem;
            line-height: .8rem;
            display: block;
            margin: 0 auto;
            text-align: center;
            color: #ffffff;
            border-radius: .05rem;
        }
    }
</style>

